/*
 * @Author: jiu yin
 * @Date: 2023-02-15 14:17:19
 * @LastEditTime: 2023-05-12 17:53:35
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \init-admin\src\router\index.js
 * jiu
 */
import { getToken } from '@/utils/auth';
import { createRouter, createWebHistory } from 'vue-router'
import { useApp_processStore } from "@/stores/app_process"
import { pinia } from '@/stores'
import routerArr from './array'
let app_processStore = useApp_processStore(pinia)
const router = createRouter({
  history: createWebHistory(),
  scrollBehavior: () => ({ y: 0 }),
  routes: [

    {
      path: '/layout',
      name: 'layout',
      component: () => import("@/layout")
    },
    // {
    //   path: '/login',
    //   name: 'login',
    //   component: () => import("@/views/login")
    // },
    {
      path: '/404',
      name: '404',
      component: () => import("@/404")
    },
    // 404 page must be placed at the end !!!
    { path: "/:catchAll(.*)", redirect: "/404", hidden: true },

    ...routerArr
  ]
})

router.beforeEach((to, from, next) => {

  //添加路由 排除首页
  if (to.path !== '/') {
    app_processStore.add(to)
  }
  next()
  //根据Token判断是否路由过滤
  // if (getToken()) {
  //   next();
  // } else {
  //   //防止无限循环
  //   if (to.name === "login") {
  //     next();
  //     return;
  //   }
  //   next({
  //     path: "/login",
  //   });
  // }
});


export default router
